// CommandGen.h

// Generovanie (vytvaranie) prikazov pre server

#ifndef COMMANDGEN_H
#define COMMANDGEN_H


#include "Common/Interfaces/Commands.h"
#include "Common/Interfaces/Communication.h"
#include "Common/Interfaces/MsgProcess.h"
// Toto je asi zle, preco z common includujeme playerov interface, nevadi to coachovi? (FUNGUJE TO!)
#include "Player/Interfaces/Synchronization.h"
#include "Common/Protocol/ServerSocket.h"
//#include "Common/World/Types.h"
//#include "Common/Module.h"
//#include "Common/Main.h"


// Posiela prikazy komunikacnej vrstve
class CommandGen : public Module, public CommandsInterface
{
	// Pointer na komunikacny interfejs
	CommunicationInterface*		m_pSocket;
	// Pointer na parser
	MsgProcessInterface*		m_pParser;
	// Synchronizacny interfejs
	SynchronizationInterface*	m_pSynchro;
	
	// Pocet poslanych sprav
	COMMAND_COUNTS m_outCounts;

	// Vystupny buffer pre posielanie sprav
	char m_outBuff[BUFFERSIZE];
	
	
#ifndef COACH
	// Skutocna strana hraca
	RealSide realSide;
#endif // COACH


protected:
	// Zaokruhlenie na 2 desatinne miesta (smerom nadol)
	inline static float RoundFloat(float fVal);

public:
	// Konstruktor
	CommandGen();
	// Destruktor
	virtual ~CommandGen()
	{
	
	}

	// Vrati toto rozhranie
	virtual Interface* GetInterface(int nTask = -1) const;
	// Prikaz pre zmenu uhlu pohladu hraca
	virtual int ChangeView(ViewWidth iWidth);
	// Prikaz pre inicializovanie jazyka CLang
	virtual int CLangInit();
	// Prikaz pre odpojenie sa od servera
	virtual int Disconnect();
	// Inicializovanie rozhrani - komunikacneho, sychronizacneho a parsera
	virtual int Init(int argc, char** argv, int nTask = -1);
	// Prikaz na opatovne pripojenie sa k serveru
	virtual int Reconnect(const char* pTeamName, unsigned uUniformNumber);
	// Prikaz na stav score
	virtual int Score();
	// Prikaz na inicializovanie komunikacie so serverom
	virtual int ServerInit(const char* teamName, bool goalie = false, const char* ver = NULL);
	// Prikaz na nastavenie skutocnej strany ihriska
	virtual void SetRealSide(RealSide rs);
	// Prikaz catch
	virtual int Catch(float fDirection);
	// Prikaz dash
	virtual int Dash(float fPower);
	// Prikaz kick
	virtual int Kick(float fPower, float fDirection);
	// Prikaz move
	virtual int Move(float fX, float fY);	
	// Prikaz tacle
	virtual int Tackle(float power);
	// Prikaz turn
	virtual int Turn(float fMoment);
	// Prikaz turn_neck
	virtual int TurnNeck(int iAngle);
	// Prikaz say
	virtual int Say(const char* pMsg);
	// Prikaz sense_body
	virtual int SenseBody();

	//loptosi
	virtual int AttentionTo(int uniformNumber);
	virtual int AttentionOff();

//	virtual int SendCommand(int, void*) { return 1; }

#ifdef COACH
	//
	virtual int ChangePlayerType(const int uniformNumber, const int type);
	//
	virtual int Eye(const char* onOff);
	//
	virtual int TeamGraphic(int i, int j, const char* lines);
	//
	virtual int TeamNames();
	
#endif // COACH

};

// Zaokruhli desatinne cislo (ako %0.2f)
// Vrati cislo zaokruhlene na 2 desatinne miesta smerom nadol (23.4567 -> 23.45)
float CommandGen::RoundFloat(float num)
{
	return (float) ((int) (100.0f * num)) / 100.0f;
}

#endif // COMMANDGEN_H
